#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
void Child()
{
    int cnt=5;
    while(cnt)
    {
        printf("I am child pid=%d ppid=%d cnt=%d\n",getpid(),getppid(),cnt);
        sleep(1);
        cnt--;
    }
}

int main()
{
    pid_t pid=fork();
    if(pid==0)
    {
        Child();
        exit(0);
    }
    if(pid>0)
    {    
        printf("I am child pid=%d ppid=%d\n",getpid(),getppid());
    }

    sleep(8);

    pid_t ret=waitpid(pid,NULL,0);
    if(ret==pid)
    {
        printf("waitpid success ret=%d\n",ret);
    }

    sleep(5);
    return 0;
}
